﻿#region Imports
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using CommonUtilities.Enums;
using CommonUtilities.Messages;
using CommonUtilities.Extensions;
#endregion

namespace PatternLocker.Controls
{
    /// <summary>
    /// Interaction logic for DirectionButton.xaml
    /// </summary>
    public partial class DirectionButton : UserControl
    {
        #region Properties
        private eButtonDirection direction = eButtonDirection.Default;
        public eButtonDirection Direction
        {
            get { return direction; }
            set
            {
                direction = value;
                switch (direction)
                {
                    case eButtonDirection.Top:
                        txtDirection.Text = "▲";
                        txtDirection.HorizontalAlignment = HorizontalAlignment.Center;
                        txtDirection.VerticalAlignment = VerticalAlignment.Top;
                        break;

                    case eButtonDirection.Bottom:
                        txtDirection.Text = "▼";
                        txtDirection.HorizontalAlignment = HorizontalAlignment.Center;
                        txtDirection.VerticalAlignment = VerticalAlignment.Top;
                        break;

                    case eButtonDirection.Left:
                        txtDirection.Text = "◄";
                        txtDirection.HorizontalAlignment = HorizontalAlignment.Center;
                        txtDirection.VerticalAlignment = VerticalAlignment.Top;
                        break;

                    case eButtonDirection.Right:
                        txtDirection.Text = "►";
                        txtDirection.HorizontalAlignment = HorizontalAlignment.Right;
                        txtDirection.VerticalAlignment = VerticalAlignment.Center;
                        break;

                    case eButtonDirection.Default:
                    default:
                        txtDirection.Text = "●";
                        txtDirection.HorizontalAlignment = HorizontalAlignment.Center;
                        txtDirection.VerticalAlignment = VerticalAlignment.Center;
                        break;
                }

                if (direction != eButtonDirection.Default)
                    txtDirection.Margin = txtDirection.Margin.MoveMargin(direction);
            }
        }

        private bool isVisible;
        public bool IsVisible
        {
            get { return isVisible; }
            set
            {
                isVisible = value;

                txtDirection.Foreground = (isVisible ? Brushes.GreenYellow : Brushes.Black);
                //grdDirection.Visibility = (Visibility)new VisibilityConverter()
                //    .Convert(isVisible, typeof(Visibility), null, Utilities.DefaultCulture);
            }
        }
        #endregion

        #region Constructors
        public DirectionButton()
        {
            InitializeComponent();
            IsVisible = false;
        }
        #endregion

        #region Events
        private void ToggleButton_CheckedChanged(object sender, RoutedEventArgs e)
        {
            MessageBoxUtil.Show(
                Debugger.IsAttached, tglDirection.IsChecked.ToString(),
                "DirectionButton :: " + Direction.ToString()); // RKD
        }

        private void txtDirectionTemplate_MouseEnter(object sender, MouseEventArgs e)
        {
            IsVisible = true;
        }

        private void txtDirectionTemplate_MouseLeave(object sender, MouseEventArgs e)
        {
            IsVisible = false;
        }
        #endregion
    }
}
